package com.cloud.mall.web;

import com.cloud.mall.dto.CategoryQueryDto;
import com.cloud.mall.dto.CategorySaveDto;
import com.cloud.mall.dto.product.CategoryDto;
import com.cloud.mall.result.GeneralResponse;
import com.cloud.mall.service.ICategoryService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author: 梁二东
 * @Date: 2025/1/8 13:33
 * @Description:
 **/
@RestController
@RequestMapping("/category")
public class CategoryController {


    @Resource
    private ICategoryService categoryService;

    /**
     * 查询商品类别接口：支持分页查询、全量查询、树状结构
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/getCategories")
    public GeneralResponse<List<CategoryDto>> getCategories(@RequestBody CategoryQueryDto queryDto) {
        return categoryService.getCategories(queryDto);
    }

    /**
     * 保存和编辑商品类别
     *
     * @param saveDto
     * @return
     */
    @PostMapping("/saveCategory")
    public GeneralResponse<String> saveCategory(@RequestBody @Valid CategorySaveDto saveDto) {
        return categoryService.saveCategory(saveDto);
    }
}
